package cn.edu.xjtu.daily.April.day_4_24;

import java.util.Scanner;

/**
 * @author Hydrion-QLz
 * @date 2022-04-24 13:33
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long bakB = b;
        long bakA = a;
        long p = sc.nextInt();
        sc.close();

        long ans = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                ans = (ans * a) % p;
            }
            b = b >> 1;
            a = (a * a) % p;
        }
        System.out.printf("%d^%d mod %d=%d", bakA, bakB, p, ans);
    }
}
